package cn.liyunqi.iot.chinatelecomunitimitate.compent.demo02;
import com.mcrazy.log.Log;
import com.mcrazy.main.McPublisher;
import org.eclipse.paho.client.mqttv3.MqttMessage;

public class PacketPublisher implements Runnable {

    private String topic = "";

    private String msg = "";

    public PacketPublisher(String topic, String msg) {
        this.topic = topic;
        this.msg = msg;
    }
    @Override
    public void run() {
        MqttMessage msg_pub = new MqttMessage(msg.getBytes());
        msg_pub.setQos(0);
        Log.err.info("=======准备发送Topic：{}========", topic);
        Log.err.info("=======准备发送Message：{}========", msg);
        try {
            McPublisher.getInstance().getMqttClient().publish(topic, msg_pub);
        } catch (Exception e) {
            Log.err.info("=======发布主题消息失败：topic: {}=========", topic);
        }
    }
}